package kr.hkit.androidcomplete02.ch16;

import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.widget.Toast;
// 따로 생성한 Fragment
public class MyAlertDialogFragment extends DialogFragment {
	
	@Override
	public Dialog onCreateDialog(Bundle savedInstanceState) {
		Bundle args = getArguments();
		String title = args.getString("title");
		String msg = args.getString("message");
		
		return new AlertDialog.Builder(getActivity())
		.setTitle(title)
		.setMessage(msg)
		.setPositiveButton("확인", new OnClickListener() {
			public void onClick(DialogInterface dialog, int which) {
				doClick(which);
			}
		})
		.setNegativeButton("취소", new OnClickListener() {
			public void onClick(DialogInterface dialog, int which) {
				doClick(which);
			}
		})
		.create();
	}
	
	protected void doClick(int which){
		// -1 : positive
		// -2 : negative
		switch(which){
		case -1:
			Toast.makeText(getActivity(), "확인버튼", Toast.LENGTH_SHORT).show();
			break;
			
		case -2:
			Toast.makeText(getActivity(), "취소버튼", Toast.LENGTH_SHORT).show();
			break;
		}
	}
}
